﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" name="viewport" content="width=device-width" />
    <title>生产管理粗纱机</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet" />
    <script src="../Content/scripts/jquery-1.11.1.min.js"></script>
    <link href="../Content/styles/font-awesome.min.css" rel="stylesheet" />
    <link href="../Content/scripts/plugins/jquery-ui/jquery-ui.min.css" rel="stylesheet" />
    <script src="../Content/scripts/plugins/jquery-ui/jquery-ui.min.js"></script>
    <link href="../Content/scripts/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <script src="../Content/scripts/bootstrap/bootstrap.min.js"></script>
    <link href="../Content/scripts/plugins/jqgrid/jqgrid.css" rel="stylesheet" />
    <link href="../Content/adminLTE/css/index.css" rel="stylesheet" />
    <link href="../Content/styles/learun-ui.css" rel="stylesheet" />
    <script src="../Content/scripts/plugins/jqgrid/grid.locale-cn.js"></script>
    <script src="../Content/scripts/plugins/jqgrid/jqgrid.min.js"></script>
    <script src="../Content/scripts/plugins/tree/tree.js"></script>
    <script src="../Content/scripts/plugins/validator/validator.js"></script>
    <script src="../Content/scripts/plugins/dialog/dialog.js"></script>
    <script src="../Content/scripts/utils/learun-ui.js"></script>
    <script src="../Content/scripts/utils/learun-form.js"></script>
    <link href="../Content/scripts/plugins/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
    <script src="../Content/scripts/plugins/bootstrap-table/bootstrap-table.js"></script>
    <script src="../Content/scripts/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <script src="../Content/scripts/plugins/layout/jquery.layout.js"></script>
    <script src="../My97DatePicker/WdatePicker.js"></script>
    <script src="../js/highcharts.js"></script>
    <script src="../js/highcharts-3d.js"></script>
    <script src="../js/getUrlParam.js"></script>

    <script src="CustomerMFGJS.js"></script>
    <style type="text/css">
        body {
            margin: 0px;
            margin-top: 10px;
        }

        .form .formTitle {
            width: 130px;
            font-size: 20px;
            padding-bottom: 35px;
        }

        .form .formValue {
            padding-bottom: 25px;
            width: 170px;
        }

        .valuestyle {
            font-size: 20px;
        }

        #title {
            font-size: 30px;
            text-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
        }

        #time {
            font-size: 20px;
            float: right;
            line-height: 50px;
            right: 40px;
            position: fixed;
            color: #65b540;
        }

        @media screen and (min-width:1281px) and (max-width:1440px) {
            .valuestyle {
                font-size: 15px;
            }

            .form .formTitle {
                font-size: 15px;
            }
        }

        #info {
            float: right;
            color: #ff0000;
            font-size: 9px;
        }

        a {
            color: skyblue;
            text-decoration: none;
            cursor: pointer;
        }

        span {
            border-radius: 100px;
        }

        .highcharts-subtitle {
            left: 260px;
        }

            .highcharts-subtitle a {
                font-size: 20px;
            }
    </style>
</head>

<body>
    <div style="text-align: center; height: 50px;">
        <span id="title">生产信息</span>
        <span id="time"></span>
    </div>
    <!--粗纱实时数据-->

    <div class="panel-Title">粗纱实时数据</div>
    <div class="titlePanel" id="customerselect">
        <div class="title-search">
            <table>
                <tr>
                    <td style="padding-left: 5px;">
                        <span>客户名称：</span>
                    </td>
                    <td style="padding-left: 5px;">
                        <select class="form-control" id="customerlist" style="width: 200px;"></select>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <table id="tb_cusha"></table>

    <script>

        $(function () {
            if (getCookie("CustomerID") !== "") {
                $("#customerselect").css('display', 'none');
                $("#title").html(getCookie("CustomerName") + "生产信息");
                //1.初始化Table
                var oTable = new TableInit();
                oTable.Init();
            }
            else {
                $.CustomerMFGjs.getCustomerList();

                $("#title").html($('#customerlist').find('option:selected').text() + "生产信息");
                //1.初始化Table
                var oTable = new TableInit();
                oTable.Init();

                $('#customerlist').on('change', function () {
                    //判断是否选取prompt属性，无返回值；
                    if ($(this).val()) {
                        $("#title").html($('#customerlist').find('option:selected').text() + "生产信息");
                        queryAll();
                    }
                });

            }
        })


        //setInterval(function () {
        //    fnDate();
        //}, 1000);


        ////js 获取当前时间
        //function fnDate() {
        //    var oDiv = document.getElementById("time");
        //    var date = new Date();
        //    var year = date.getFullYear();//当前年份
        //    var month = date.getMonth();//当前月份
        //    var data = date.getDate();//天
        //    var hours = date.getHours();//小时
        //    var minute = date.getMinutes();//分
        //    var second = date.getSeconds();//秒
        //    var time = year + "-" + fnW((month + 1)) + "-" + fnW(data) + " " + fnW(hours) + ":" + fnW(minute) + ":" + fnW(second);
        //    oDiv.innerHTML = time;
        //}


        //补位 当某个字段不是两位数时补0
        function fnW(str) {
            var num;
            str > 9 ? num = str : num = "0" + str;
            return num;
        }

        //读取cookie
        function getCookie(name) {
            var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
            if (arr != null) return decodeURI(arr[2]); return null;
        };


        var TableInit = function () {
            var oTableInit = new Object();
            var time = $("#time").text();
            console.log(time)
            //初始化Table
            oTableInit.Init = function () {
                $('#tb_cusha').bootstrapTable({
                    url: '../MFG/MFGCusha.ashx?Action=getshishijilulist&time=' + time,        //请求后台的URL（*）
                    method: 'POST',                      //请求方式（*）
                    contentType: "application/x-www-form-urlencoded",
                    toolbar: '#toolbar',                //工具按钮用哪个容器
                    striped: true,                      //是否显示行间隔色
                    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                    pagination: false,                   //是否显示分页（*）
                    sortable: true,                     //是否启用排序
                    sortOrder: "asc",                   //排序方式
                    queryParams: oTableInit.queryParams, //参数
                    //queryParamsType: "limit", //参数格式,发送标准的RESTFul类型的参数请求
                    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber: 1,                       //初始化加载第一页，默认第一页
                    pageSize: 10,                       //每页的记录行数（*）
                    pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                    search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                    strictSearch: true,
                    showColumns: true,                  //是否显示所有的列
                    showRefresh: true,                  //是否显示刷新按钮
                    minimumCountColumns: 2,             //最少允许的列数
                    clickToSelect: true,                //是否启用点击选中行
                    height: 600,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                    uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                    showToggle: true,                    //是否显示详细视图和列表视图的切换按钮
                    cardView: false,                    //是否显示详细视图
                    detailView: false,                   //是否显示父子表
                    rowStyle: function (row, index) {
                        //这里有5个取值代表5中颜色['active', 'success', 'info', 'warning', 'danger'];
                        var strclass = "";
                        if (row.zhuangtai == "1") {
                            strclass = 'success';//还有一个active
                        }
                        else if (row.zhuangtai == "2") {
                            strclass = 'warning';
                        }
                        else if (row.zhuangtai == "3") {
                            strclass = 'danger';
                        }
                        else {
                            return {};
                        }
                        return { classes: strclass }
                    },
                    columns: [{
                        field: 'EquNo',
                        title: '机台号',
                        sortable: true,
                        width: 100
                    }, {
                        field: 'Kind',
                        title: '品种'
                    }, {
                        field: 'Chanliangm',
                        title: '当班产量(m)'
                    }, {
                        field: 'Chanliangkg',
                        title: '当班产量(kg)'
                    }, {
                        field: 'tongguansudu',
                        title: '筒管速度'
                    }, {
                        field: 'dingyisudu',
                        title: '锭翼速度'
                    }, {
                        field: 'luolasudu',
                        title: '罗拉速度'
                    }, {
                        field: 'shengjiangsudu',
                        title: '升降速度'
                    }, {
                        field: 'tongguanwendu',
                        title: '筒管温度'
                    }, {
                        field: 'dingyiwendu',
                        title: '锭翼温度'
                    }, {
                        field: 'luolawendu',
                        title: '罗拉温度'
                    }, {
                        field: 'shengjiangwendu',
                        title: '升降温度'
                    }, {
                        field: 'longjinweizhi',
                        title: '龙筋位置'
                    }, {
                        field: 'dangqianchangdu',
                        title: '当前纺纱长度'
                    }, {
                        field: 'dangqianxiaolv',
                        title: '当前效率'
                    }, {
                        field: 'chesu',
                        title: '车速'
                    }, {
                        field: 'zhuangtai',
                        title: '设备状态',
                        formatter: function (value, row, index) {
                            if (value == 1) {
                                return '<span class=\"label label-success\">开车</span>';
                            }
                            else if (value == 2) {
                                return '<span class=\"label label-warning\">落纱</span>';
                            }
                            else if (value == 3) {
                                return '<span class=\"label label-danger\">停车</span>';
                            }
                        }
                    }]
                });
            };

            //得到查询的参数
            oTableInit.queryParams = function (params) {
                if (getCookie("CustomerID") !== "") {
                    var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        CustomerID: getCookie("CustomerID"),
                        pageSize: params.limit, //页面大小
                        offset: params.offset, //页码
                        sort: params.sort, //排序列名
                        sortOrder: params.order
                        //排位命令（desc，asc
                    };
                    return temp;
                }
                else {
                    var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        CustomerID: $('#customerlist').find('option:selected').text(),
                        pageSize: params.limit, //页面大小
                        offset: params.offset, //页码
                        sort: params.sort, //排序列名
                        sortOrder: params.order//排位命令（desc，asc）

                    };
                    return temp;
                }

            };
            return oTableInit;
        };



        setInterval(function () {
            //queryAll();
        }, 10000);


        function queryAll() {
            $('#tb_cusha').bootstrapTable('removeAll');
            var data = "";
            if (getCookie("CustomerID") !== "") {
                data = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    CustomerID: getCookie("CustomerID"),
                    //pageSize: params.limit, //页面大小
                    //offset: params.offset, //页码
                    // sort: params.sort, //排序列名
                    sortOrder: 'asc'//排位命令（desc，asc）
                };
            }
            else {
                data = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    CustomerID: $('#customerlist').find('option:selected').text(),
                    //pageSize: params.limit, //页面大小
                    //offset: params.offset, //页码
                    // sort: params.sort, //排序列名
                    sortOrder: 'asc'//排位命令（desc，asc）
                };

            }

            $.ajax({
                type: "post",
                //url不用说了吧，否则不知道向服务器哪个接口发送并请求
                url: '../MFG/MFGCusha.ashx?Action=getshishijilulist&time=' + $("#time").text(),
                data: data,
                async: true,
                //超时时间
                timeout: 30000,
                success: function (data) {
                    console.log($.parseJSON(data).rows);
                    var datajson = $.parseJSON(data).rows;
                    tableData = [];
                    for (var i = 0; i < datajson.length; i++) {
                        tableData.push({
                            //这里也就是data-field的名称，getDate是服务器返回的字段名
                            EquNo: datajson[i].EquNo,
                            Kind: datajson[i].Kind,
                            Chanliangm: datajson[i].Chanliangm,
                            Chanliangkg: datajson[i].Chanliangkg,
                            tongguansudu: datajson[i].tongguansudu,
                            dingyisudu: datajson[i].dingyisudu,
                            luolasudu: datajson[i].luolasudu,
                            shengjiangsudu: datajson[i].shengjiangsudu,
                            tongguanwendu: datajson[i].tongguanwendu,
                            dingyiwendu: datajson[i].dingyiwendu,
                            luolawendu: datajson[i].luolawendu,
                            shengjiangwendu: datajson[i].shengjiangwendu,
                            longjinweizhi: datajson[i].longjinweizhi,
                            dangqianchangdu: datajson[i].dangqianchangdu,
                            dangqianxiaolv: datajson[i].dangqianxiaolv,
                            chesu: datajson[i].dangqianxiaolv,
                            zhuangtai: datajson[i].zhuangtai
                        })
                    }

                    $('#tb_cusha').bootstrapTable('append', tableData);
                }
            });
        }

        /*

* ajax 函数，处理 ajax 请求

* @param function callback 回调函数

* @因为要和服务器交互，所以必须在服务器环境运行，不能在硬盘上直接打开

*/

        function ajax(callback) {

            if (typeof callback != 'function') return;

            var ajaxObject;

            try {

                ajaxObject = new XMLHttpRequest();

            } catch (e) {

                try {

                    ajaxObject = new ActiveXObject('Microsoft.XMLHTTP');

                } catch (e) {

                }

            }

            if (!ajaxObject) return;

            if (ajaxObject.overrideMimeType) {

                ajaxObject.overrideMimeType('text/html');

            }

            //location.href可以换成其他url，但必须是同一个站点的链接，并且文件存在

            ajaxObject.open('get', location.href);

            ajaxObject.send(null);

            ajaxObject.onreadystatechange = function () {

                if (ajaxObject.readyState == 4) {

                    if (ajaxObject.status == 200) {

                        callback(ajaxObject);

                    }

                }

            };

        }

        /*

         * 获取时间并动态刷新

        */

        function getTime() {

            ajax(

                function (ao) {

                    //只需要AJAX一次，将服务器时间获取后以毫米为单位保存到一个变量中

                    _timestamp = Date.parse(ao.getResponseHeader('Date'));

                    _timestamp = _timestamp.toString().match(/^\d$/) ? _timestamp : new Date().getTime();

                    //设置定时器每过一秒动态刷新一次时间

                    setInterval(

                        function () {

                            //这里可以自定义时间显示格式

                            //document.getElementById('time').innerHTML = new Date(_timestamp)
                            var oDiv = document.getElementById("time");
                            var date = new Date(_timestamp);
                            var year = date.getFullYear();//当前年份
                            var month = date.getMonth();//当前月份
                            var data = date.getDate();//天
                            var hours = date.getHours();//小时
                            var minute = date.getMinutes();//分
                            var second = date.getSeconds();//秒
                            var time = year + "-" + fnW((month + 1)) + "-" + fnW(data) + " " + fnW(hours) + ":" + fnW(minute) + ":" + fnW(second);
                            oDiv.innerHTML = time;
                            _timestamp += 1000;

                        },

                        1000

                    );

                }

            );

        }

        window.onload = getTime;
    </script>
</body>

</html>
